function [Vulner_node] = gretna_vulnerability_weight(W)

%==========================================================================
% This function is used to calculate nodal vulnerability for a weighted 
% graph or network G.
% 
%
% Syntax: function [Vulner_node] = gretna_vulnerability(W)
% 
% Input:
%               W:            
%                   The adjacency matrix of G (N*N, symmetric).
%
% Output:
%     Vulner_node:  
%                   The vulnerability of each node in G.
%
% Yong HE,     NKLCNL, BNU, BeiJing, 2011/03/12
% Jinhui WANG, NKLCNL, BNU, BeiJing, 2011/10/23, Jinhui.Wang.1982@gmail.com
%==========================================================================

W = W - diag(diag(W));
W = abs(W);
N = length(W);

[averlp, ~] = gretna_node_shortestpathlength_weight(W);
Lp_raw = averlp;

Lp_removenode = zeros(N,1);

for i =1:N
    W_removenode = W;
    W_removenode(i,:) = [];
    W_removenode(:,i) = [];
    [averlp, ~] = gretna_node_shortestpathlength_weight(W_removenode);
    Lp_removenode(i) = averlp;
end

Vulner_node = 100*(Lp_removenode - Lp_raw)/Lp_raw;

return